//--------------------------------------------------------------------------
// $Id: Assertion.java 2 2006-08-20 04:04:26Z zendragon $
//--------------------------------------------------------------------------
// Copyright 2006 Social Brain Foundation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//--------------------------------------------------------------------------

package org.socialbrain.openid;

/**
 * @author <a href="http://erning.net/">Zhang Erning</a>
 * @version $Id: Assertion.java 2 2006-08-20 04:04:26Z zendragon $
 */
public class Assertion extends KeyValuePairs
{
    /**
     * Creates a new positive assertion.
     */
    public Assertion()
    {
        put(Constants.PARAM_MODE, Constants.MODE_ID_RES);
    }

    /**
     * Creates a new negative assertion.
     *
     * @param immediate
     */
    public Assertion(boolean immediate)
    {
        put(Constants.PARAM_MODE, immediate ? Constants.MODE_ID_RES : Constants.MODE_CANCEL);
    }

    public Assertion(KeyValuePairs pairs)
    {
        super(pairs);
    }

    //

    public String getMode()
    {
        return get(Constants.PARAM_MODE);
    }

    // Positive

    public void setIdentity(String value)
    {
        put(Constants.PARAM_IDENTITY, value);
    }

    public String getIdentity()
    {
        return get(Constants.PARAM_IDENTITY);
    }

    public void setReturnTo(String value)
    {
        put(Constants.PARAM_RETURN_TO, value);
    }

    public String getReturnTo()
    {
        return get(Constants.PARAM_RETURN_TO);
    }

    public void setNonce(String value)
    {
        put(Constants.PARAM_NONCE, value);
    }

    public String getNonce()
    {
        return get(Constants.PARAM_NONCE);
    }

    public void setInvalidateHandle(String value)
    {
        put(Constants.PARAM_INVALIDATE_HANDLE, value);
    }

    public String getInvalidateHandle()
    {
        return get(Constants.PARAM_INVALIDATE_HANDLE);
    }

    public void setAssocHandle(String value)
    {
        put(Constants.PARAM_ASSOC_HANDLE, value);
    }

    public String getAssocHandle()
    {
        return get(Constants.PARAM_ASSOC_HANDLE);
    }

    public void setSigned(String value)
    {
        put(Constants.PARAM_SIGNED, value);
    }

    public String getSigned()
    {
        return get(Constants.PARAM_SIGNED);
    }

    public void setSig(byte[] value)
    {
        putAsByteArray(Constants.PARAM_SIG, value);
    }

    public byte[] getSig()
    {
        return getAsByteArray(Constants.PARAM_SIG);
    }

    // Negative

    public void setUserSetupUrl(String value)
    {
        put(Constants.PARAM_USER_SETUP_URL, value);
    }

    public String getUserSetupUrl()
    {
        return get(Constants.PARAM_USER_SETUP_URL);
    }

    //

    public boolean isPositive()
    {
        return !Constants.MODE_CANCEL.equals(getMode())
                && !contains(Constants.PARAM_USER_SETUP_URL);
    }

    public boolean isNegative()
    {
        return Constants.MODE_CANCEL.equals(getMode())
                || contains(Constants.PARAM_USER_SETUP_URL);
    }
}
